package home

import (
	// "fmt"
	_ "myblog/models"

	"github.com/astaxie/beego"
	"github.com/astaxie/beego/orm"
)

type BaseController struct {
	beego.Controller
}

func (c *BaseController) Prepare() {
	c.get_article_class()
}

func (c *BaseController) Finish() {
	// fmt.Println("结束后释放一些资源")
}

/**
*调用文章分类
 */
func (c *BaseController) get_article_class() {
	o := orm.NewOrm()
	// 获取 QuerySeter 对象，article_class 为表名
	var lists []orm.Params
	_, err := o.QueryTable("article_class").Values(&lists)

	if err == nil {
		// var article models.Article
		for k, v := range lists {
			// 查询文章数量
			tagCount, _ := o.QueryTable("article").Filter("article_class_id", v["ArticleclassId"]).Count()
			lists[k]["tagCount"] = tagCount
		}
		c.Data["articleClassList"] = lists
	}
	// fmt.Print(lists, "\n")

}
